# -*- shell-script -*-

# 00pci - Generic PCI-related functions.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2002, 2003, 2004, 2005

# Maintained by  Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 00pci,v 1.1 2006/04/11 18:38:28 emunson Exp $

# This module is always loaded.
true || return 0

######################################################################

pci_get_config_filename ()
{
    # Sets: pci_config
    pci_config=""

    local pci_addr="$1"

    local d="/proc/bus/pci"

    local t="${pci_addr//://}" # Replace colons with slashes.
    case "$t" in
	(*/*/*) t="${t/\//:}" ;; # Put back first colon too many slashes.
    esac
    
    local conf="${d}/${t}"
    # Try removing domain if file doesn't exist.
    [ -f "$conf" ] || conf="${d}/${t#0000:}"

    [ -f "$conf" ] && pci_config="$conf"
}

pci_render_vpd ()
{
    local ibm_vpd_chunk="$1"
    local node="$2"

    local vpd_subdirs
    vpd_subdirs_list_hook "$node"

    if [ -f "$ibm_vpd_chunk" -a -z "$vpd_subdirs" ] ; then
	debug_cmd ibm_vpd_render "$ibm_vpd_chunk" "$node"
    else
	return 1
    fi
}

